clear all

*********Set working directory and load data
local user: env USERNAME
if "`user'" == "ENTERYOURNAME"  cd "SETYOURDIRECTORY"
else if "`user'" == "sagomm"  cd "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\" 

use "Data\w9_conjoint.dta"

******Install necesarry user-written commands
do "Scripts\functions\function_conjoint.do"
do "Scripts\functions\function_addplot.do"


********* OUTCOME - BINARY (VOTE FOR A, VOTE FOR B - both possible) *******

************ One Actor: Policy Packages**********
//estimate conjoint coefficients
reg binary ///
	ib1.reporting##ib1.sanction##ib4.regulation b1.monitoring year if actor < 5, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(reporting=(3(-1)1) sanction=(3(-1)1) regulation=(1(1)4)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, ///
title("One actor", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlabel(,labsize(small)) ///
	xlab(0.2(0.1)0.8, format(%2.1f)) ///
	xline(0.5, lc(black)) ///
	coefl( ///
		1._at = "By 2030" ///
		2._at = "By 2035" ///
		3._at = "By 2040" ///
		4._at = "No rules" ///
		5._at = "By 2030" ///
		6._at = "By 2035" ///
		7._at = "By 2040" ///
		8._at = "No rules" ///
		9._at = "By 2030" ///
		10._at = "By 2035" ///
		11._at = "By 2040" ///
		12._at = "No rules" ///
		13._at = "By 2030" ///
		14._at = "By 2035" ///
		15._at = "By 2040" ///
		16._at = "No rules" ///
		17._at = "By 2030" ///
		18._at = "By 2035" ///
		19._at = "By 2040" ///
		20._at = "No rules" ///
		21._at = "By 2030" ///
		22._at = "By 2035" ///
		23._at = "By 2040" ///
		24._at = "No rules" ///
		25._at = "By 2030" ///
		26._at = "By 2035" ///
		27._at = "By 2040" ///
		28._at = "No rules" ///
		29._at = "By 2030" ///
		30._at = "By 2035" ///
		31._at = "By 2040" ///
		32._at = "No rules" ///
		33._at = "By 2030" ///
		34._at = "By 2035" ///
		35._at = "By 2040" ///
		36._at = "No rules" ///
		) ///
	groups( ///
		1._at 2._at 3_.at 4._at = `""Severe" "Sanc""' ///
		5._at 6._at 7_.at 8._at = `""Moderate" "Sanc""' ///
		9._at 10._at 11._at 12._at = `""No" "Sanc""' ///
		13._at 14._at 15_.at 16._at = `""Severe" "Sanc""' ///
		17._at 18._at 19_.at 20._at = `""Moderate" "Sanc""' ///
		21._at 22._at 23._at 24._at = `""No" "Sanc""' ///
		25._at 26._at 27_.at 28._at = `""Severe" "Sanc""' ///
		29._at 30._at 31_.at 32._at = `""Moderate" "Sanc""' ///
		33._at 34._at 35._at 36._at = `""No" "Sanc""', ///
		angle(rvertical)) ///
	heading(1._at = `"{bf:Many conditions}"' ///
	13._at = `"{bf:Some conditions}"' ///
	25._at = `"{bf:No conditions}"') ///
	 yscale(alt axis(2)) ysize(10) xsize(6) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	 text(25 -0.32 "{it:Stringency}", ///
			orientation(vertical) s(medsmall)) ///
			graphregion(color(white)) ///
	name(fig_1, replace) 
	addplot fig_1:pcarrowi 50 -0.28 0 -0.28, ///
	graphregion(color(white)) ///
		norescaling lc(gs4) mc(gs4) lp(shortdash)
	
//Save Figure 
gr export "Plots\SI_Chapter2_factorial_A_binary.png", as(png) ///
	name("fig_1") replace	
	

************ All Actors: Policy Packages**********
//estimate conjoint coefficients
reg binary ///
	ib1.reporting##ib1.sanction##ib4.regulation b1.monitoring year if actor == 7, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(reporting=(3(-1)1) sanction=(3(-1)1) regulation=(1(1)4)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, ///
	title("All actors", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.2(0.1)0.8, format(%2.1f)) ///
	xlabel(,labsize(small)) ///
	xline(0.5, lc(black)) ///
	coefl( ///
		1._at = "By 2030" ///
		2._at = "By 2035" ///
		3._at = "By 2040" ///
		4._at = "No rules" ///
		5._at = "By 2030" ///
		6._at = "By 2035" ///
		7._at = "By 2040" ///
		8._at = "No rules" ///
		9._at = "By 2030" ///
		10._at = "By 2035" ///
		11._at = "By 2040" ///
		12._at = "No rules" ///
		13._at = "By 2030" ///
		14._at = "By 2035" ///
		15._at = "By 2040" ///
		16._at = "No rules" ///
		17._at = "By 2030" ///
		18._at = "By 2035" ///
		19._at = "By 2040" ///
		20._at = "No rules" ///
		21._at = "By 2030" ///
		22._at = "By 2035" ///
		23._at = "By 2040" ///
		24._at = "No rules" ///
		25._at = "By 2030" ///
		26._at = "By 2035" ///
		27._at = "By 2040" ///
		28._at = "No rules" ///
		29._at = "By 2030" ///
		30._at = "By 2035" ///
		31._at = "By 2040" ///
		32._at = "No rules" ///
		33._at = "By 2030" ///
		34._at = "By 2035" ///
		35._at = "By 2040" ///
		36._at = "No rules" ///
		) ///
	groups( ///
		1._at 2._at 3_.at 4._at = `""Severe" "Sanc""' ///
		5._at 6._at 7_.at 8._at = `""Moderate" "Sanc""' ///
		9._at 10._at 11._at 12._at = `""No" "Sanc""' ///
		13._at 14._at 15_.at 16._at = `""Severe" "Sanc""' ///
		17._at 18._at 19_.at 20._at = `""Moderate" "Sanc""' ///
		21._at 22._at 23._at 24._at = `""No" "Sanc""' ///
		25._at 26._at 27_.at 28._at = `""Severe" "Sanc""' ///
		29._at 30._at 31_.at 32._at = `""Moderate" "Sanc""' ///
		33._at 34._at 35._at 36._at = `""No" "Sanc""', ///
		angle(rvertical)) ///
	heading(1._at = `"{bf:Many conditions}"' ///
	13._at = `"{bf:Some conditions}"' ///
	25._at = `"{bf:No conditions}"') ///
	 yscale(alt axis(2)) ysize(10) xsize(6) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
			graphregion(color(white)) ///
	name(fig_2, replace) 
	
//Save Figure 
gr export "Plots\SI_Chapter2_factorial_B_binary.png", as(png) ///
	name("fig_2") replace	
	
//Combine graphs
gr combine ///
	fig_1 ///
	fig_2, ///
	graphregion(color(white)) ///
	name(fig1fig2_comb, replace)


	
	
	
	
	
	

********* OUTCOME - CHOICE (EITHER A OR B) *******

************ One Actor: Policy Packages**********
//estimate conjoint coefficients
reg choice ///
	ib1.reporting##ib1.sanction##ib4.regulation b1.monitoring year if actor < 5, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(reporting=(3(-1)1) sanction=(3(-1)1) regulation=(1(1)4)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, ///
title("One actor", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlabel(,labsize(small)) ///
	xlab(0.3(0.1)0.7, format(%2.1f)) ///
	xline(0.5, lc(black)) ///
	coefl( ///
		1._at = "By 2030" ///
		2._at = "By 2035" ///
		3._at = "By 2040" ///
		4._at = "No rules" ///
		5._at = "By 2030" ///
		6._at = "By 2035" ///
		7._at = "By 2040" ///
		8._at = "No rules" ///
		9._at = "By 2030" ///
		10._at = "By 2035" ///
		11._at = "By 2040" ///
		12._at = "No rules" ///
		13._at = "By 2030" ///
		14._at = "By 2035" ///
		15._at = "By 2040" ///
		16._at = "No rules" ///
		17._at = "By 2030" ///
		18._at = "By 2035" ///
		19._at = "By 2040" ///
		20._at = "No rules" ///
		21._at = "By 2030" ///
		22._at = "By 2035" ///
		23._at = "By 2040" ///
		24._at = "No rules" ///
		25._at = "By 2030" ///
		26._at = "By 2035" ///
		27._at = "By 2040" ///
		28._at = "No rules" ///
		29._at = "By 2030" ///
		30._at = "By 2035" ///
		31._at = "By 2040" ///
		32._at = "No rules" ///
		33._at = "By 2030" ///
		34._at = "By 2035" ///
		35._at = "By 2040" ///
		36._at = "No rules" ///
		) ///
	groups( ///
		1._at 2._at 3_.at 4._at = `""Severe" "Sanc""' ///
		5._at 6._at 7_.at 8._at = `""Moderate" "Sanc""' ///
		9._at 10._at 11._at 12._at = `""No" "Sanc""' ///
		13._at 14._at 15_.at 16._at = `""Severe" "Sanc""' ///
		17._at 18._at 19_.at 20._at = `""Moderate" "Sanc""' ///
		21._at 22._at 23._at 24._at = `""No" "Sanc""' ///
		25._at 26._at 27_.at 28._at = `""Severe" "Sanc""' ///
		29._at 30._at 31_.at 32._at = `""Moderate" "Sanc""' ///
		33._at 34._at 35._at 36._at = `""No" "Sanc""', ///
		angle(rvertical)) ///
	heading(1._at = `"{bf:Many conditions}"' ///
	13._at = `"{bf:Some conditions}"' ///
	25._at = `"{bf:No conditions}"') ///
	 yscale(alt axis(2)) ysize(10) xsize(6) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
	 text(25 -0.16 "{it:Stringency}", ///
			orientation(vertical) s(medsmall)) ///
			graphregion(color(white)) ///
	name(fig_1, replace) 
	addplot fig_1:pcarrowi 50 -0.13 0 -0.13, ///
	graphregion(color(white)) ///
		norescaling lc(gs4) mc(gs4) lp(shortdash)
	
//Save Figure 
gr export "Plots\SI_Chapter2_factorial_A.png", as(png) ///
	name("fig_1") replace	
	

************ All Actors: Policy Packages**********
//estimate conjoint coefficients
reg choice ///
	ib1.reporting##ib1.sanction##ib4.regulation b1.monitoring year if actor == 7, ///
	cluster(PubId)
	
eststo reg_int_all

*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est res reg_int_all
margins, at(reporting=(3(-1)1) sanction=(3(-1)1) regulation=(1(1)4)) post
est sto mar_int_all

//Plot package figure
coefplot mar_int_all, ///
	title("All actors", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	mc(edkblue) ciopts(lc(edkblue)) ///
	xtitle("Pr(Selecting Proposal)") ///
	xlab(0.3(0.1)0.7, format(%2.1f)) ///
	xlabel(,labsize(small)) ///
	xline(0.5, lc(black)) ///
	coefl( ///
		1._at = "By 2030" ///
		2._at = "By 2035" ///
		3._at = "By 2040" ///
		4._at = "No rules" ///
		5._at = "By 2030" ///
		6._at = "By 2035" ///
		7._at = "By 2040" ///
		8._at = "No rules" ///
		9._at = "By 2030" ///
		10._at = "By 2035" ///
		11._at = "By 2040" ///
		12._at = "No rules" ///
		13._at = "By 2030" ///
		14._at = "By 2035" ///
		15._at = "By 2040" ///
		16._at = "No rules" ///
		17._at = "By 2030" ///
		18._at = "By 2035" ///
		19._at = "By 2040" ///
		20._at = "No rules" ///
		21._at = "By 2030" ///
		22._at = "By 2035" ///
		23._at = "By 2040" ///
		24._at = "No rules" ///
		25._at = "By 2030" ///
		26._at = "By 2035" ///
		27._at = "By 2040" ///
		28._at = "No rules" ///
		29._at = "By 2030" ///
		30._at = "By 2035" ///
		31._at = "By 2040" ///
		32._at = "No rules" ///
		33._at = "By 2030" ///
		34._at = "By 2035" ///
		35._at = "By 2040" ///
		36._at = "No rules" ///
		) ///
	groups( ///
		1._at 2._at 3_.at 4._at = `""Severe" "Sanc""' ///
		5._at 6._at 7_.at 8._at = `""Moderate" "Sanc""' ///
		9._at 10._at 11._at 12._at = `""No" "Sanc""' ///
		13._at 14._at 15_.at 16._at = `""Severe" "Sanc""' ///
		17._at 18._at 19_.at 20._at = `""Moderate" "Sanc""' ///
		21._at 22._at 23._at 24._at = `""No" "Sanc""' ///
		25._at 26._at 27_.at 28._at = `""Severe" "Sanc""' ///
		29._at 30._at 31_.at 32._at = `""Moderate" "Sanc""' ///
		33._at 34._at 35._at 36._at = `""No" "Sanc""', ///
		angle(rvertical)) ///
	heading(1._at = `"{bf:Many conditions}"' ///
	13._at = `"{bf:Some conditions}"' ///
	25._at = `"{bf:No conditions}"') ///
	 yscale(alt axis(2)) ysize(10) xsize(6) ///
	 r2title("{bf:  }", orientation(rvertical)) ///
			graphregion(color(white)) ///
	name(fig_2, replace) 
	
//Save Figure 
gr export "Plots\SI_Chapter2_factorial_B.png", as(png) ///
	name("fig_2") replace	
	

